package com.syy.flow;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;

public class FlowReducer extends Reducer<Text, FlowBean, Text, FlowBean> {
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        long sum_upFlow = 0,sum_DownFlow = 0;

        for (FlowBean flowBean : values) {
            sum_upFlow += flowBean.getUpFlow();
            sum_DownFlow += flowBean.getDownFlow();
        }

        FlowBean flowBean = new FlowBean(sum_upFlow, sum_DownFlow);

        context.write(key, flowBean);
    }
}
